local ty_1v2_sc = fk.CreateSkill {
    name = "ty_1v2_sc&",
}

Fk:loadTranslationTable {
    ["ty_1v2_sc&"] = "寿春",
    [":ty_1v2_sc&"] = "结束阶段，你可以选择一项，不能与上次选择的选项相同：1.回复点体力；2.将手牌调整至X(X为存活角色数，至少为你的体力值)。",

    ["ty_1v2_sc1"] = "回复 1 点体力",
    ["ty_1v2_sc2"] = "将手牌调整至 %arg 张",
}

ty_1v2_sc:addEffect(fk.EventPhaseStart, {
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Finish
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local n = math.max(player.hp, #room.alive_players)
        local all_choices = { "ty_1v2_sc1", "ty_1v2_sc2:::" .. n }
        local choices = { "ty_1v2_sc1", "ty_1v2_sc2:::" .. n }
        if player:getMark("shouchun_jiaxue") ~= 0 then
            table.removeOne(choices, "ty_1v2_sc1")
        end
        if player:getMark("shouchun_tiaozheng") ~= 0 then
            table.removeOne(choices, "ty_1v2_sc2:::" .. n)
        end
        if #choices == 0 then return end
        local choice = room:askToChoice(player,
            {
                all_choices = all_choices,
                choices = choices,
                prompt = "寿春：请选择一项",
                skill_name = ty_1v2_sc.name
            })
        if choice then
            event:setCostData(self, { choice = choice })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local choice = event:getCostData(self).choice
        local n = math.max(player.hp, #room.alive_players)
        if choice == "ty_1v2_sc2:::" .. n then
            if n > player:getHandcardNum() then
                player:drawCards(n - player:getHandcardNum(), ty_1v2_sc.name)
            elseif n < player:getHandcardNum() then
                room:askToDiscard(player,
                    {
                        min_num = player:getHandcardNum() - n,
                        max_num = player:getHandcardNum() - n,
                        include_equip = false,
                        skill_name = ty_1v2_sc.name,
                        cancelable = false
                    })
            end
            room:setPlayerMark(player, "shouchun_jiaxue", 0)
            room:setPlayerMark(player, "shouchun_tiaozheng", 1)
        else
            room:recover {
                who = player,
                num = 2,
                recoverBy = player,
                skillName = ty_1v2_sc.name
            }
            room:setPlayerMark(player, "shouchun_jiaxue", 1)
            room:setPlayerMark(player, "shouchun_tiaozheng", 0)
        end
    end,
})

return ty_1v2_sc
